#ifndef __FONT_BDF_H
#define __FONT_BDF_H

#include <config.h>

#ifdef FONT_BDF_SUPPORT

#include <types.h>

typedef unsigned short MWIMAGEBITS;	/* bitmap image unit size*/
/* MWIMAGEBITS helper macros*/
#define MWIMAGE_WORDS(x)	(((x)+15)/16)	/* image size in words*/
#define MWIMAGE_BYTES(x)	(MWIMAGE_WORDS(x)*sizeof(MWIMAGEBITS))
#define	MWIMAGE_BITSPERIMAGE (sizeof(MWIMAGEBITS) * 8)
#define	MWIMAGE_BITVALUE(n)	((MWIMAGEBITS) (((MWIMAGEBITS) 1) << (n)))
#define	MWIMAGE_FIRSTBIT	(MWIMAGE_BITVALUE(MWIMAGE_BITSPERIMAGE - 1))
#define	MWIMAGE_TESTBIT(m)	((m) & MWIMAGE_FIRSTBIT)
#define	MWIMAGE_SHIFTBIT(m)	((MWIMAGEBITS) ((m) << 1))

/* builtin C-based proportional/fixed font structure */
/* based on The Microwindows Project http://microwindows.org */
typedef struct {
	char *name;            /* font name*/
	int	 maxwidth;	       /* max width in pixels*/
	int  height;		       /* height in pixels*/
	int	 ascent;		       /* ascent (baseline) height*/
	int	 firstchar;	       /* first character in bitmap*/
	int	 size;		         /* font size in glyphs*/
	MWIMAGEBITS *bits;		 /* 16-bit right-padded bitmap data*/
	unsigned long *offset; /* offsets into bitmap data*/
	unsigned char *width;  /* character widths or NULL if fixed*/
	int	 defaultchar;	     /* default char (not glyph index)*/
	long bits_size;	       /* # words of MWIMAGEBITS bits*/
	char *facename;	       /* facename of font*/
	char *copyright;	     /* copyright info for loadable fonts*/
	int	pixel_size;
	int	descent;
	int	fbbw, fbbh, fbbx, fbby;
} BDF_FONT;

int convbdf(char *path, int code);
void bdf_free_font(BDF_FONT *pf);
BDF_FONT * bdf_read_font(char *path);
int bdf_read_header(FILE *fp, BDF_FONT *pf);
int bdf_read_bitmaps(FILE *fp, BDF_FONT *pf);
char *bdf_getline(FILE *fp, char *buf, int len);
MWIMAGEBITS bdf_hexval(unsigned char *buf, int ndx1, int ndx2);
u8 *bdf_load_bmp(BDF_FONT *pf, u32 code, COLOR *bg, COLOR *fg);

#endif /* FONT_BDF_SUPPORT */
#endif /* __FONT_BDF_H */
